package org.xukai.rest.common;

import java.util.List;

/**
 * Created by gaosijie on 16/3/16.
 */
public class AjaxResponse<T> {

    /**
     * 请求成功
     */
    public static final Integer SUCCESS=200;

    /**
     * 请求失败
     */
    public static final Integer FALSE=300;

    /**
     * 默认成功消息
     */
    public static final String DEFAULT_SUCCESS_MSG="操作成功！";

    /**
     * 默认成功消息
     */
    public static final String DEFAULT_FALSE_MSG="操作失败！";

    /**
     * 默认tabid
     */
    public static final String DEFAULT_TAB_ID="_blank";


    /**
     * 请求结果
     * SUCCESS/FALSE
     */
    public Integer statusCode;

    /**
     * 返回消息
     */
    public String message;

    /**
     * tabid
     */
    public String navTabId;

    /**
     * 返回对象
     */
    public Object data;

    /**
     * 返回List
     */
    public List<T> list;
    
    public AjaxResponse() {
		this.statusCode = SUCCESS;
	}

	/**
     * 成功消息填充
     */
    public void successResult() {
        successResult(DEFAULT_TAB_ID);
    }

    /**
     * 成功消息填充
     * @param navTabId tabid
     */
    public void successResult(String navTabId) {
        successResult(navTabId, DEFAULT_SUCCESS_MSG);
    }

    /**
     * 成功消息填充
     * @param navTabId tabid
     * @param message  消息
     */
    public void successResult(String navTabId, String message) {
        setStatusCode(AjaxResponse.SUCCESS);
        setMessage(message);
        setNavTabId(navTabId);
    }


    /**
     * 失败消息填充
     */
    public void falseResult() {
        falseResult(DEFAULT_TAB_ID);
    }

    /**
     * 失败消息填充
     * @param navTabId tabid
     */
    public void falseResult(String navTabId) {
        falseResult(navTabId, DEFAULT_FALSE_MSG);
    }

    /**
     * 失败消息填充
     * @param navTabId tabid
     * @param message  消息
     */
    public void falseResult(String navTabId, String message) {
        setStatusCode(AjaxResponse.FALSE);
        setMessage(message);
        setNavTabId(navTabId);
    }

    public Integer getStatusCode() {
        return statusCode;
    }

    public void setStatusCode(Integer statusCode) {
        this.statusCode = statusCode;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public String getNavTabId() {
        return navTabId;
    }

    public void setNavTabId(String navTabId) {
        this.navTabId = navTabId;
    }
}
